package recorder;

import java.io.*;

public class recorderComponent implements IGravar {
	
	//atributos
	protected boolean recordStarted;
	protected String recordLine;
	protected String file;
	
	//Construtor
	public recorderComponent(){
		this.file =  "MeetingLog" + System.currentTimeMillis() + ".txt";
		this.recordStarted = true;
		this.recordLine = "Iniciando Gravação" + System.currentTimeMillis();
		try{
			this.saveFile(this.file, this.recordLine, true);
		}catch(IOException e){
				e.printStackTrace();
		}
	}
	
	//gets e sets
	public String getRecordLine() {
		return recordLine;
	}
	public void setRecordLine(String recordLine) {
		this.recordLine = recordLine;
	}
	public boolean isRecordStarted() {
		return recordStarted;
	}
	protected void setRecordStarted(boolean recordStarted) {
		this.recordStarted = recordStarted;
	}

	
	//métodos
		
	public boolean saveFile(String file, String logLine, boolean add) throws IOException {

		boolean result;
		
		try{
			FileWriter fw = new FileWriter(file, add);

			fw.write(logLine);
			fw.close();
			result = true;
		}catch(IOException e){
			result = false;
			e.getMessage();
		}
		return result;
	}
	
}
